package com.sc.common.entity;

import com.github.pagehelper.PageInfo;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@Data
public class Page<T> implements Serializable {

    public static final int defaultCurrent = 1;
    public static final int defaultSize = 10;

    private static final long serialVersionUID = 1L;

    private Integer totalPage;

    private Integer currentPage;

    private Integer size;

    private Long totalElements;
    private  List<T> list;
    public Page() {
    }

    public Page(PageInfo<T> helperPage) {
        this.totalElements = helperPage.getTotal()==0?1:helperPage.getTotal();
        this.totalPage = helperPage.getPages();
        this.currentPage = helperPage.getPageNum()==0?1:helperPage.getPageNum();
        this.size = helperPage.getPageSize();
        this.list = helperPage.getList();
    }

    public Page(com.baomidou.mybatisplus.plugins.Page<T> tPage) {
        Integer total = tPage.getTotal();
        this.totalElements =total.longValue()==0?1:total.longValue();
        this.totalPage = tPage.getPages()==0?1:tPage.getPages();
        this.currentPage = tPage.getCurrent()==0?1:tPage.getCurrent()                     ;
        this.size = tPage.getSize();
        this.list =tPage.getRecords();
    }

    public Page(com.github.pagehelper.Page<T> bdpage) {
        this.totalElements=bdpage.getTotal()==0?1:bdpage.getTotal();
        this.totalPage=bdpage.getPages()==0?1:bdpage.getPages();
        this.size=bdpage.getPageSize();
        this.list=bdpage.getResult();
        this.currentPage=bdpage.getPageNum()==0?1:bdpage.getPageNum();
    }
}
